package com.ding;

import org.ding.Main;
import org.ding.domain.Repository.StudentRepository;
import org.ding.infra.util.RedisUtils;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.scripting.support.ResourceScriptSource;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Collections;


@SpringBootTest(classes = Main.class)
@RunWith(SpringRunner.class)
public class test {

    @Autowired
    private RedisTemplate<String, String> template;
    @Test
    void runTest() {
        System.out.println("test success!");
    }

    @Test
    void testConnection() {
        template.opsForValue().set("ding","123");
        System.out.println(template.opsForValue().get("ding"));
    }

    @Test
    void testLua() {
        try {
            DefaultRedisScript<Long> longDefaultRedisScript = new DefaultRedisScript<>();
            longDefaultRedisScript.setResultType(Long.class);
            longDefaultRedisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("lua/SetAndGetKey.lua")));
            Long prizeStork = template.execute(longDefaultRedisScript, Collections.singletonList("prize_stork"), "10", "20");
            System.out.println(prizeStork);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Autowired
    RedisUtils utils;

    @Test
    public void testRedis() {
    }

    @Autowired
    public StudentRepository service;
    @Test
    void testMybatis() {
        System.out.println(service.getAllStudent());
    }
}
